# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=pycurl
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=7.45.2
pkgrel=2
pkgdesc='A Python 3.x interface to libcurl (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:MIT')
url='https://github.com/pycurl/pycurl'
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-curl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        001-pycurl-setup-fix.patch
        002-pycurl-docdir-path-fix.patch)
sha256sums=('5730590be0271364a5bddd9e245c9cc0fb710c4cbacbdd95264a3122d23224ca'
            'cd2ea373f576b35967f99e6e183a92faf3fb0908456be2157cbf4ec44ba648d8'
            '4c9cc653e3037cc89b851958cb193d05f7580d654cf57a15fe69f5e4a3e7727a')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-pycurl-setup-fix.patch
  patch -p1 -i ${srcdir}/002-pycurl-docdir-path-fix.patch

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build --with-openssl \
    --curl-config=${MINGW_PREFIX}/bin/curl-config
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 COPYING-MIT "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
